package com.singzi.leetcode.N2300;

import java.util.*;

public class T2289 {
    public static void main(String[] args) {
        Solution solution = new Solution();
        int []nums = {5,3,4,4,7,3,6,11,8,5,11};
        System.out.println(solution.totalSteps(nums));

    }
}
class Solution {
    public int totalSteps(int[] nums) {
        int ans = 0;
        Deque<Integer>deque = new ArrayDeque<>();
        int max = 0;
        for(int num:nums){
            if(deque.isEmpty()){
                deque.add(num);
            }else if(deque.peek() > num){
                max++;
            }else {
                ans = Math.max(max, ans);
                deque.pop();
                deque.add(num);
                max = 0;
            }
        }
        return ans;

    }

    public int totalSteps1(int[] nums) {

        int ans = 0;
        Queue<Integer> queue1 = new LinkedList<>();
        Queue<Integer> queue2 = new LinkedList<>();
        int temp;
        for(int num:nums){
            queue1.add(num);
        }
        boolean flag = false;
        while (true){
            flag = true;
            int num1 = queue1.remove();
            queue2.add(num1);
            temp = num1;
            while (!queue1.isEmpty()){
                int num2 = queue1.remove();
                if(num2 < temp) {
                    flag = false;
                }else {
                    queue2.add(num2);
                }
                temp = num2;
            }
            if(flag) break;
            ans++;
            flag = true;
            num1 = queue2.remove();
            queue1.add(num1);
            temp = num1;
            while (!queue2.isEmpty()){
                int num2 = queue2.remove();
                if(num2 < temp) {
                    flag = false;
                }else {
                    queue1.add(num2);
                }
                temp = num2;
            }
            if(flag) break;
            ans++;
        }
        while (!queue2.isEmpty()){
            int a = queue2.remove();
            System.out.println(a);
        }
        while (!queue1.isEmpty()){
            int a = queue1.remove();
            System.out.println(a);
        }

        return  ans;
    }
}


